package com.mslinn.yumifier.model {
    import com.adobe.utils.IntUtil;
    
    import mx.collections.ArrayCollection;
    
	/**  The data model that the UI Tag will display. */ 
	public class Tag  {
        [Bindable] private static var app:AppModel = AppModel.getInstance();
		public var count:int;
		public var href:String;
		public var name:String;
		
		
		public function Tag(count:int, name:String) {
            this.count = int(count);
            this.name = name;
			this.href = app.serviceUrl + "/u:" + app.userId + "/t:" + name;
		}
        
        public function clone(tag:Tag):Tag {
            return new Tag(count, new String(name));
        }

        /** Ignores tags without posts */
		public static function decode(xml:XML):ArrayCollection {
            var tags:Array = [];
            var total:int = 0;
            for each (var tagXml:XML in xml..tag) {
                var count:int = parseInt((tagXml.@count).toString());
                //trace(tagXml.@tag, tagXml.@count);
                if (count>0) {
                    var tag:Tag = new Tag(count, tagXml.@tag);
                    tags.push(tag);
                    total += count;
                }
            }
            app.linkCount = total;
            return new ArrayCollection(tags);
		}
		
		public function toString():String {
			return "Tag [ name = " + name + ", size = " + count + " ]";
		}
	}
}
